package com.demo.zlb.sso.login.utils;

import com.alibaba.xxpt.gateway.shared.client.http.ExecutableClient;
import org.springframework.beans.factory.annotation.Value;

/**
 * 浙政钉请求接口sdk
 *
 * @author shiyuchen
 * @date 2023-04-12
 */
public class DingRequestUtil {
    /**
     * 域名
     */
    @Value("${zzdingTalk.domainName}")
    private String domainName;
    /**
     * ak
     */
    @Value("${zzdingTalk.appKey}")
    private String appKey;
    /**
     * sk
     */
    @Value("${zzdingTalk.appSecret}")
    private String appSecret;
    /**
     * https
     */
    @Value("${zzdingTalk.protocal}")
    private String protocal;

    public DingRequestUtil() {
    }

    public DingRequestUtil(String domainName, String appKey, String appSecret, String protocal) {
        this.domainName = domainName;
        this.appKey = appKey;
        this.appSecret = appSecret;
        this.protocal = protocal;
    }

    public static ExecutableClient getConnect() {
        return new DingRequestUtil().connect();
    }

    public static ExecutableClient otherConnect(String domainName, String appKey, String appSecret, String protocal) {
        return new DingRequestUtil(domainName, appKey, appSecret, protocal).connect();
    }

    /**
     * 设置sdk属性
     *
     * @return
     */
    public ExecutableClient connect() {
        ExecutableClient executableClient = ExecutableClient.getInstance();
        //DomainName不同环境对应不同域名，示例为sass域名
        executableClient.setDomainName(domainName);
        // https
        executableClient.setProtocal(protocal);
        //应用App Key
        executableClient.setAccessKey(appKey);
        //应用App Secret
        executableClient.setSecretKey(appSecret);
        //executableClient要单例，并且使用前要初始化，只需要初始化一次
        executableClient.init();
        return executableClient;
    }

    //static {
    //    executableClient = ExecutableClient.getInstance();
    //    //DomainName不同环境对应不同域名，示例为sass域名
    //    executableClient.setDomainName(domainName);
    //    executableClient.setProtocal(protocal);
    //    //应用App Key
    //    executableClient.setAccessKey(appKey);
    //    //应用App Secret
    //    executableClient.setSecretKey(appSecret);
    //    //executableClient要单例，并且使用前要初始化，只需要初始化一次
    //    executableClient.init();
    //}

/*    public static void main(String[] args) {
        //executableClient保证单例
        IntelligentGetClient intelligentGetClient = executableClient.newIntelligentGetClient("/mozi/fusion/getPropertiesByOrgTypeCode");
        OapiMoziFusionGetPropertiesByOrgTypeCodeRequest oapiMoziFusionGetPropertiesByOrgTypeCodeRequest = new OapiMoziFusionGetPropertiesByOrgTypeCodeRequest();
        //组织类型code
        oapiMoziFusionGetPropertiesByOrgTypeCodeRequest.setOrgTypeCode("字符串");
        //租户id
        oapiMoziFusionGetPropertiesByOrgTypeCodeRequest.setTenantId(tenantId);
        //获取结果
        OapiMoziFusionGetPropertiesByOrgTypeCodeResponse apiResult = intelligentGetClient.get(oapiMoziFusionGetPropertiesByOrgTypeCodeRequest);
    }*/
}
